/**
 * Copyright 2009-2011 xiaonei.com All right reserved.
 * This software is the confidential and proprietary information of Xiaonei.com ("Confidential Information"). 
 * You shall not disclose such Confidential Information and shall use it only in accordance with the terms of the license agreement you entered into with Xiaonei.com.
 * Create by XiaoNeiAntiSpamTeam
 *
 */

package com.xiaonei.testice.testami.client;

import Ice.Communicator;
import Ice.LocalException;
import Ice.ObjectPrx;
import Ice.Util;

import com.xiaonei.testice.testami.AMI_Printer_printString;
import com.xiaonei.testice.testami.PrinterPrx;
import com.xiaonei.testice.testami.PrinterPrxHelper;
import com.xiaonei.testice.util.IceUtil;

/**
 * @ClassName: AMIPrinterClient
 * @Description: AMIPrinter客户算
 * @author shaohui.liu shaohui.liu@opi-corp.com
 * @date Jan 28, 2010 10:44:22 AM
 * 
 */
public class AMIPrinterClient {

    /**
     * 服务代理
     */
    private PrinterPrx printerPrx = null;

    public static AMIPrinterClient instance = new AMIPrinterClient();

    public AMIPrinterClient() {
        Communicator communicator = Util.initialize(IceUtil.initData());
        ObjectPrx objectPrx = communicator.stringToProxy("AMIPrinter@AMIPrinter");
        // 配额对象代理
        // objectPrx = objectPrx.ice_locatorCacheTimeout(60);
        printerPrx = PrinterPrxHelper.uncheckedCast(objectPrx);
    }

    /**
     * 
     * @Title: printStringAsync
     * @Description: 异步打印消息
     * @param @param message
     * @return void
     * @throws
     */
    public void printStringAsync(String message) {
        AMI_Printer_printString amiPrinterPrintString = new AMI_Printer_printString() {

            @Override
            public void ice_response() {
                System.out.println("response finished!");
            }

            @Override
            public void ice_exception(LocalException ex) {
                System.out.println("response exception!");
            }
        };
        printerPrx.printString_async(amiPrinterPrintString, message);
    }

    /**
     * 
     * @Title: printerString
     * @Description: 打印消息
     * @param @param message
     * @return void
     * @throws
     */
    public void printerString(String message) {
        printerPrx.printString(message);
    }
}
